function reEmoji(str) {
    var reg = /\/images\/emoji\/[a-z]*_[a-z0-9]*\/[0-9]*@2x\.png/g;
    var matchArr = str.match(reg);
    if(!matchArr){
        return str;
    }
    for(var i = 0; i < matchArr.length; i++){
        for (var j in EMOJI_MAP) {
            if (EMOJI_MAP[j] == matchArr[i]) {
                str = str.replace('<img src="'+matchArr[i]+'"style="width: width:28px;"/>', j);
            }
        }
    }
    return str;
}
var vue = new Vue({
    el:"#app",
    data:{
        page:{},
        comments:[]
    },
    methods:{
        orderChange:function (orderType) {
            var el = event.currentTarget;
            $(".orderBy").closest("div").removeClass("on");
            $(el).closest("div").addClass("on");

            $("#orderType").val(orderType);

            this.commPage(1);

        },
        commPage:function (page) {
            var param = getParams();
            var p = $("#travelForm").serialize() + "&currentPage=" + page;
            //游记分页
            ajaxGet("/travel/query?"+p,{}, function (data) {
                vue.page = data.data;
                buildPage(vue.page.number, vue.page.totalPages, vue.doPage)
            })
        },
        doPage:function(page){
            this.commPage(page);
        },
        conditionChange:function(){
            this.commPage(1);
        }
    },
    mounted:function () {
        //游记分页
        ajaxGet("/travel/query",{}, function (data) {
            vue.page = data.data;
            buildPage(vue.page.number, vue.page.totalPages, vue.doPage)
        })

        //最新动态
        ajaxGet("/travel/newComments",{},function (data) {
            for (var j = 0; j < data.data.length; j++) {
                data.data[j].content = reEmoji(data.data[j].content);
            }
            vue.comments = data.data;
        })
    }
});

